/**
 * 
 */
package np.com.baralsujan.algorithms;

import np.com.baralsujan.algorithms.BinaryTree.Node;

import org.junit.Assert;
import org.junit.Test;


/**
 * @author sbara1
 *
 */
public class TestBinaryTree {

	@Test
	public void testNewNode() {
		BinaryTree binaryTree = new BinaryTree(5);
		Node node = binaryTree.getRoot();
		Assert.assertEquals(5, node.getValue());
	}

	@Test
	public void testInsert() {
		BinaryTree binaryTree = new BinaryTree();
		binaryTree.insert(10);
		binaryTree.insert(3);
		Assert.assertEquals(2, binaryTree.size());
		binaryTree.insert(15);
		binaryTree.insert(5);
		binaryTree.insert(8);
		binaryTree.insert(2);
		binaryTree.insert(1);
		binaryTree.insert(12);
		binaryTree.insert(-1);
		Assert.assertEquals(9, binaryTree.size());
	}

	@Test
	public void testMaxDepth() {
		BinaryTree binaryTree = new BinaryTree();
		binaryTree.insert(10);
		binaryTree.insert(3);
		binaryTree.insert(15);
		Assert.assertEquals(2, binaryTree.maxDepth());
		binaryTree.insert(5);
		binaryTree.insert(8);
		Assert.assertEquals(4, binaryTree.maxDepth());
		binaryTree.insert(2);
		binaryTree.insert(1);
		binaryTree.insert(12);
		binaryTree.insert(-1);
		Assert.assertEquals(5, binaryTree.maxDepth());
	}

	@Test
	public void testMinValue() {
		BinaryTree binaryTree = new BinaryTree();
		binaryTree.insert(10);
		binaryTree.insert(3);
		binaryTree.insert(15);
		Assert.assertEquals(3, binaryTree.minValue());
		binaryTree.insert(5);
		binaryTree.insert(8);
		binaryTree.insert(2);
		Assert.assertEquals(2, binaryTree.minValue());
		binaryTree.insert(1);
		Assert.assertEquals(1, binaryTree.minValue());
		binaryTree.insert(12);
		binaryTree.insert(-1);
		Assert.assertEquals(-1, binaryTree.minValue());
	}

	@Test
	public void testPrintTree() {
		BinaryTree binaryTree = new BinaryTree();
		binaryTree.insert(4);
		binaryTree.insert(2);
		binaryTree.insert(5);
		binaryTree.insert(3);
		binaryTree.insert(1);
		binaryTree.printTree();
		binaryTree.printPostOrder();
	}
}
